var Config = require('./Config');
let imgList = require('./../../imglist');
// 项目初始化的一些函数
var initProject = function () {
    var webFn = function () {
        if (_UA) {
            $('.web-empty').addClass('mobile');
        } else {
            $('.web-empty').removeClass('mobile');
        }
    };
    webFn();
    window.addEventListener('resize', webFn);
};

// 加载页对象
var LoadViewController = function () {
    // 公共变量
    let _that = this;

    // 私有变量
    var _private = {};

    _private.pageEl = $('.m-loading');
    _private.loadWrap = _private.pageEl.find('.loadProcess');
    console.log(_private.loadWrap);
    _private.isInit = false;
    Config.pageImgs.img = [];

    // 初始化，包括整体页面
    _private.init = function () {
        if (_private.isInit === true) {
            return;
        }
        initProject();
        // 加载体现在页面上
        _private.processLineEl = _private.loadWrap.find('.inner');
        _private.isInit = true;
        for (let i = 0; i < imgList.length; i++) {
            Config.pageImgs.imgs[i] = {};
            Config.pageImgs.imgs[i].name = imgList[i].name;
            Config.pageImgs.imgs[i].url = require(`../../img/${imgList[i].url}`);
        }
        _private.gload = new Config.Preload(Config.pageImgs);
        _private.gload.onloading = function (p) {
            _private.processLineEl.css('width', p + '%');
            // 视频部分渲染上去
        };
        _private.gload.onfail = function (msg) {
            // console.log(msg);
        };
        _private.gload.onload = function () {
            _that.hide();
        };
    };

    // 显示
    _that.show = function () {
        _private.pageEl.show();
    };

    // 隐藏
    _that.hide = function () {
        _that.onhide && _that.onhide();
        _private.pageEl.hide();
    };

    // 执行加载
    _that.load = function () {
        _private.gload.load();
    };
    _private.init();
};

module.exports = LoadViewController;
